npm scripts
記述方法
npm init -yしたら以下の内容が記述されている
code:package.json
{
...
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
...
}
あらかじめ予約されているキーワードがある
code:keyword
prepublish prepare prepublishOnly
prepack postpack
publish postpublish
preinstall install postinstall
preuninstall uninstlal postuninstall
preversion version postversion
pretest test posttest
prestop stop poststop
prestart start poststart
prerestart restart postrestart
preshrinkwrap shrinkwrap postshrinkwrap
それぞれのタスクは、何かしらのタイミングで実行される
独自のタスクを定義する場合は、これ以外のキーワードを指定する必要がある
見かけた独自のタスク
build
clean
format, fmt
lint
testing
:を使って階層化してるケースもよく見る
format:scss
実行方法
$ npm run hoge
以下4つは、runがなくても起動できる
$ npm start
$ npm test
$ npm stop
$ npm restart
gulp/gruntの問題
プラグイン作者への依存
デバッグでのストレス
バラバラのドキュメント
npm scriptsへの誤解
npm scriptsは難しいコマンドスキルを要する
npm scriptsはそれほどパワフルではない
gulpのストリームは、高速なビルドには不可欠である
npm scriptsはクロスプラットフォームではない
デメリット
package.jsonにコメントを書けない
変数をサポートしていない
2019-04
表がわかりやすい
webpackが使われだして、gulpやgruntの価値が相対的に下がったのだろうか
参考